home *** CD-ROM | disk | FTP | other *** search
/ Java Certification Exam Guide / McGrawwHill-JavaCertificationExamGuide.iso / pc / Web Links and Code / rev / chap6 / q4.java < prev    next >
Encoding:
Java Source  |  1997-05-08  |  977 b   |  43 lines

  1. class A {
  2.    public static void main(String[] args) {
  3.       Integer myInt = new Integer(5);
  4.       Integer otherInt;
  5.       otherInt = myInt;
  6.       if (otherInt == myInt)
  7.          System.out.println("equal");
  8.       else
  9.          System.out.println("not equal");
  10.    }
  11. }
  12.  
  13. class B {
  14.    public static void main(String[] args) {
  15.       Integer myInt = new Integer(5);
  16.       Integer anotherInt = new Integer(5);
  17.       if (anotherInt == myInt)
  18.          System.out.println("equal");
  19.       else
  20.          System.out.println("not equal");
  21.    }
  22. }
  23.  
  24. class C {
  25.    public static void main(String[] args) {
  26.       MyClass mc1 = new MyClass(1);
  27.       if (mc1.operatorEquals(mc1))
  28.          System.out.println("equal");
  29.       else
  30.          System.out.println("not equal");
  31.    }
  32. }
  33.  
  34. class MyClass extends Object {
  35.    int value;
  36.    MyClass(int value) {
  37.       this.value = value;
  38.    }
  39.    boolean operatorEquals(MyClass test) {
  40.       return (this == test);
  41.    }
  42. }
  43.